#include <iostream>
#include <string>
#include <string.h>
#include <list>
#include <algorithm>
using namespace std;

class Student{
public:
    // 构造函数
    Student(char *name,int age, int chinese, int math, int english)
    :_name(new char[strlen(name) + 1]())
    ,_age(age)
    ,_chinese(chinese)
    ,_math(math)
    ,_english(english)
    {
        strcpy(_name,name);
    }

    void print(){
        cout << "================" << endl;
        cout << "_name=" << _name << endl;
        cout << "_age=" << _age << endl;
        cout << "_chinese=" << _chinese << endl;
        cout << "_math=" << _math << endl;
        cout << "_english=" << _english << endl;
    }

    // 写一个获得总分的成员函数访问私有成员获得
    int getSum() const{
        return _chinese + _math + _english;
    }

    int getChinese() const{
        return _chinese; 
    }


private:
    char *_name;
    int _age;
    int _chinese;
    int _math;
    int _english;
};


// 自定义排序规则：总成绩降序 → 语文成绩降序
bool compareStudents(const Student& a, const Student& b) {
    if (a.getSum() != b.getSum()) {
        return a.getSum() > b.getSum();  // 总成绩高的在前
    } else {
        return a.getChinese() > b.getChinese();  // 总成绩相同，语文高的在前
    }
}

void test(){
    // 创建学生对象链表
    // 假设现在就写5个学生信息吧输入5个学生信息
    // 进行预设的测试内容
    list<Student> students = {
        Student((char *)"小红", 18, 90, 86, 90),
        Student((char *)"小蓝", 19, 85, 95, 90),
        Student((char *)"小紫", 20, 91, 85, 90),
        Student((char *)"小绿", 18, 86, 94, 90)
    };
    
    students.sort(compareStudents);
    
    for(auto & ll : students){
        ll.print();
        cout << "_sum=" <<ll.getSum() << endl;
    }
}

int main(int atgc, char * argv[])
{
    test();
    return 0;
}

